package com.example.lottery.common.exception;

import com.example.lottery.common.errorcode.ErrorCode;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * com.example.lottery.common.errorcode.ControllerErrorCodeConstants 错误码
 */

/**
 * 统一异常处理会将ControllerException做为参数，会调用属性值给统一返回结果初始化
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class ControllerException extends RuntimeException {
    /**
     * 和错误码的属性一样，错误码给异常进行初始化
     */
    private Integer code;
    private String msg;

    public ControllerException() {
        super();
    }
    /**
     * throw new RuntimeException 时初始化 因此要有构造方法
     */
    public ControllerException(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }
    public ControllerException(ErrorCode errorCode) {
        this.code = errorCode.getCode();
        this.msg = errorCode.getMsg();
    }
}
